﻿

#pragma once

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stdexcept>
#include <assert.h>


#pragma warning(push)
#pragma warning( disable : 4290 )

namespace ksini
{


	//! \brief  m_key + m_value for ini-file.
	class IniKeyValue {
	private:

		std::string m_key;
		std::string m_value;
		std::string m_comment_line;

	public:



		IniKeyValue() 
		{

		}

		IniKeyValue(const std::string& skey, const std::string& svalue, const std::string& sComment) throw(std::runtime_error) 
			: m_key(skey), m_value(svalue), m_comment_line(sComment)  
		{
			 set_key(skey);
			 set_value(svalue);
			 set_comment_line(sComment);
		}


		~IniKeyValue() 
		{

		}

		std::string makeKeyValueLine() const
		{
			std::string res;
			res += m_key;
			res += "=";
			res += m_value;
			return res;
		}

		const std::string& get_key() const
		{
			return m_key;
		}

		void set_key(const std::string& key) throw(std::runtime_error)
		{
			std::string temp = key;
			for(size_t c=0; c<temp.length(); c++)
			{
				if( (temp[c]=='\n') )
				{
					throw std::runtime_error("bad key value ");
				}
			}

			m_key = temp;
		}

		const std::string& get_value() const 
		{
			return m_value;
		}

		void set_value( const std::string& val )    throw(std::runtime_error)
		{
			std::string temp = val;
			for(size_t c=0; c<temp.length(); c++)
			{
				if( (temp[c]=='\n') )
				{
					throw std::runtime_error("bad key value ");
				}
			}

			m_value = temp;
		}

		const std::string& get_comment_line() const 
		{
			return m_comment_line;
		}

		void set_comment_line( const std::string& comment_line )    throw(std::runtime_error)
		{
			std::string temp = comment_line;
			for(size_t c=0; c<temp.length(); c++)
			{
				if( (temp[c]=='\n') )
				{
					//throw std::runtime_error("bad key value ");
					temp[c] = ' ';
				}
			}

			m_comment_line = temp;
		}
 

	};




}

#pragma warning(pop)

